<?php
class Sosweb_Util_Common_ArrayFilter
{
	public static function filter($data, $key, $cond)
	{
		if($data == null || count($data) == 0)
		{
			return null;
		}
		else
		{
			$result = array();
			
			foreach ($data as $k=>$v)
			{
				if($v->$key == $cond)
				{
					array_push($result, $v); 
				}			
			}
			
			return $result;
		}
	}
	
	public static function partial($data, $returnColumns = null, $omitColumns = null)
	{
	    if (!$data) 
	    {
            return false;
        }
        
        $returnObject = array();

        if ($returnColumns !== null) 
        {
            $availableColumns = array_keys($data);
            
            foreach ((array) $returnColumns as $returnColumn) 
            {
                if (in_array($returnColumn, $availableColumns)) 
                {
                    $returnObject[$returnColumn] = $data[$returnColumn];
                }
            }
            
            return $returnObject;

        } 
        elseif (null !== $omitColumns) 
        {
            $omitColumns = (array) $omitColumns;
            
            foreach ($data as $resultColumn => $resultValue) 
            {
                if (!in_array($resultColumn, $omitColumns)) 
                {
                    $returnObject[$resultColumn] = $resultValue;
                }
            }
            
            return $returnObject;

        } 
        else 
        {
            return $data;
        }		
	}
}
?>